<?php
/**
 *
 * @purpose: 对“通知”类型中子类型为3(新增留言)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_type3_encoder() {
	$fields = array("msg_sender_id");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	return serialize(array(
			"msg_sender_id" => $msg_sender_id,
			));
}

function msg_notice_type3_decoder() {
	#这里不改动, begins
	$fields = array("id","receiverid","content","createTime","changeFlag","fmt");
	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}
	#这里不改动, ends

	#将encoder函数返回值解出来，即得到data[key1],data[key2],...
	$data     = unserialize($content);

	#业务逻辑
	$msg_sender_id  = $data['msg_sender_id'];


	$users_infos = UCModUserInfo::getUserInfos(array($msg_sender_id), array(USERINFO_NICKNAME));

	$seduser_nickname = htmlspecialchars($users_infos[$msg_sender_id][USERINFO_NICKNAME]);
	$seduser_nickname == '' && $seduser_nickname = $msg_sender_id;

	$sender_url = get_user_home_url($msg_sender_id);
	$sender     = "<a href=\"{$sender_url}\" target='_blank'>{$seduser_nickname}</a>";


	if ($fmt == 'line') {
		return sprintf("用户%s 给你留言了，赶快看看去吧！", $sender);

	} else if ($fmt == 'box') {
		$html = sprintf("用户%s 给你<a href=\"/home/message/home/%d\" target=\"blank\">留言</a>了，赶快看看去吧！", $sender, $receiverid);
		return '<div class="font14">' . $html . '</div>';

	} else {
		return '';
	}
}


